﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class MyCenter : Page
{
    MyDbHelper mydb = new MyDbHelper();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetUserinfo();
        }
    }

    private void GetUserinfo()
    {
        DataSet ds = mydb.DM_GetDateSet("select * from sys_loginuser where usercode='" + Session["UserCode"] + "'");
        if (ds.Tables[0].Rows.Count > 0)
        {
            DataRow dr = ds.Tables[0].Rows[0];
            this.txtusercode.Text = dr["usercode"].ToString();
            this.txtusername.Text = dr["username"].ToString();
            this.txtpwd.Text = SDKSecurity.DESDecrypt(dr["upassword"].ToString(), "km141201");
            this.txtqq.Text = dr["qq"].ToString();
            this.txtweixin.Text = dr["weixin"].ToString();
            this.txtmobile.Text = dr["mobile"].ToString();
            if (bool.Parse(dr["block"].ToString()))
            {
                lblsatus.Text = "已启用";
            }
            else
            {
                lblsatus.Text = "已停用";
            }
        }
        else
        {
            this.txtusercode.Text = "";
            this.txtusername.Text = "";
            this.txtpwd.Text = "";
            this.txtqq.Text = "";
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //保存
        if (this.txtusercode.Text == "")
        {
            Response.Write("<script type='text/javascript'>alert('用户编号不能为空！')</script>");
            return;
        }
        if (this.txtusername.Text == "")
        {
            Response.Write("<script type='text/javascript'>alert('用户名称不能为空！')</script>");
            return;
        }
        if (this.txtpwd.Text == "")
        {
            Response.Write("<script type='text/javascript'>alert('密码不能为空！')</script>");
            return;
        }

        string sql = @"update sys_loginuser set username ='"+txtusername.Text+@"',
                                                upassword='" + SDKSecurity.DESEncrypt(this.txtpwd.Text, "km141201") + @"',
                                                qq='" +this.txtqq.Text+@"',
                                                weixin='"+this.txtweixin.Text+@"',
                                                mobile='"+this.txtmobile.Text+@"',
                                                modifydate='" + DateTime.Now + @"' 
                                               where usercode='" + Session["UserCode"] + "'";
        if (mydb.DM_ExecuteNonQuery(sql) != -1)
        {
            Response.Write("<script type='text/javascript'>alert('保存成功！')</script>");
        }
    }
}